/**
 * ServiceAccessLogAdvisor.java
 * 
 * Copyright@2015 OVT Inc. All rights reserved. 
 * 
 * May 29, 2015
 */
package com.ovt.doorbell.payment.api.advisor;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ovt.doorbell.payment.common.log.Logger;
import com.ovt.doorbell.payment.common.log.LoggerFactory;
import com.ovt.doorbell.payment.common.utils.DataConvertUtils;
import com.ovt.doorbell.payment.dao.config.AppProperties;
import com.ovt.doorbell.payment.dao.constant.LoggerConstants;

/**
 * ServiceAccessLogAdvisor
 * 
 * @Author zhi.liu
 * @Version 1.0
 * @See
 * @Since [OVT Cloud Platform]/[API] 1.0
 */
@Component
@Aspect
public class ServiceAccessLogAdvisor
{
    private static final Logger logger = LoggerFactory
            .getLogger(LoggerConstants.SERVICE_ACCESS_LOGGER);
    
    private static final String POINTCUT = "execution(public * com.ovt.api.controller."
            + "ServiceAccessController.*(..)) "
            + "OR execution(* com.ovt.service.accessor.ServiceAccessorImpl.*(..)) "
            + "OR execution(* com.ovt.service.accessor.http.HttpServiceCaller.invoke(..))";

    @Autowired
    private AppProperties appProperties;

    @Before(value = POINTCUT)
    public void logEntering(JoinPoint jp)
    {
        if (!appProperties.logServiceAccessEnable)
        {
            return;
        }

        logger.entering(jp.getClass().getName(), jp.getSignature().getName(),
                DataConvertUtils.toString(jp.getArgs()));

    }

    @AfterReturning(value = POINTCUT, returning = "returnValue")
    public void logExiting(JoinPoint jp, Object returnValue)
    {
        if (!appProperties.logServiceAccessEnable)
        {
            return;
        }

        logger.exiting(jp.getClass().getName(), jp.getSignature().getName(),
                returnValue);
    }


}
